<template>
  <div class="app-container">
    <div align="center" style="margin: 40px;">
      <el-input v-model="listQuery.productCode" placeholder="产品编码" style="width: 200px;margin-left: 2%" class="filter-item" @keyup.enter.native="handleFilter" />
      <el-input v-model="listQuery.productName" placeholder="产品名称" style="width: 200px;margin-left: 2%" class="filter-item" @keyup.enter.native="handleFilter" />
      <el-date-picker
        v-model="listQuery.month"
        type="month"
        style="margin-left: 2%"
        placeholder="选择月"
      />
      <el-button v-waves class="filter-item" style="width: 100px;margin-left: 2%" type="primary" icon="el-icon-search" @click="handleFilter">
        搜索
      </el-button>
    </div>
    <el-table
      v-loading="listLoading"
      :data="list"
      element-loading-text="Loading"
      height="800"
      style="width: 100%">
      <el-table-column type="expand">
        <template slot-scope="datas">
          <el-table
            :data="datas.row.child"
            element-loading-text="Loading"
            height="300"
            style="width: 100%"
          >
            <el-table-column prop="item" label="类别" width="180">
              <template slot-scope="param">
                {{ param.row.item }}
              </template>
            </el-table-column>
            <el-table-column align="center" label="工序名称">
               <el-table-column   v-for="(item, index) in datas.row.process" width="200px" :label="item" align="center">
                <template slot-scope="param">
                  {{ param.row.process[index] }}
                </template>
              </el-table-column>
            </el-table-column>
            <el-table-column prop="sum" label="总计">
              <template slot-scope="param">
                {{ param.row.sum }}
              </template>
            </el-table-column>
          </el-table>
        </template>
      </el-table-column>
      <el-table-column label="工件名称" align="center" prop="workpieceName">
        <template slot-scope="scope">
          {{ scope.row.productName }}
        </template>
      </el-table-column>
      <el-table-column label="工件编码" align="center" prop="workpieceCode">
        <template slot-scope="scope">
          {{ scope.row.productCode }}
        </template>
      </el-table-column>
    </el-table>
<!--    <pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getList" />-->
  </div>
</template>
<style>
  *{font-size: 12px;}
</style>

<script>
import { fetchAllData } from '@/api/quality'
import Pagination from '@/components/Pagination'

export default {
  components: { Pagination },
  filters: {
    statusFilter(status) {
      const statusMap = {
        published: 'success',
        draft: 'gray',
        deleted: 'danger'
      }
      return statusMap[status]
    }
  },
  data() {
    return {
      list: null,
      listLoading: true,
      total: 0,
      listQuery: {
        page: 1,
        limit: 10,
        month: new Date(),
        productCode: '',
        productName: ''
      },
      value: new Date(),
      processhand: [],
      datas: [
        {
          item: '合格',
          process: [1, 2, 3],
          check_product: 0,
          sum: 0
        },
        {
          item: '不合格',
          process: [1, 2, 3],
          check_product: 0,
          sum: 0
        },
        {
          item: '合格率',
          process: [1, 2, 3],
          check_product: 0,
          sum: 0
        }
      ]
    }
  },
  created() {
    this.getList()
    console.log('---' + this.list)
  },
  methods: {
    getList() {
      // 这一句是把时间转化为定的时间字符串 2019-09
      this.listQuery.month = this.listQuery.month.getFullYear() + '-' + Number(this.listQuery.month.getMonth() + 1)
      this.listLoading = true
      fetchAllData(this.listQuery).then(response => {
        this.list = response.data.items
        this.total = response.data.total
        // this.processhand = this.list[0].process
        // this.datas = this.list[0].child

        // Just to simulate the time of the request
        setTimeout(() => {
          this.listLoading = false
        }, 1.5 * 1000)
      })
    },
    handleFilter() {
      this.listQuery.page = 1
      this.getList()
    }
  }
}

</script>
